home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_ShrinkMenu.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  3KB  |  97 lines

  1. /*
  2. **  GadTools layout toolkit
  3. **
  4. **  Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **      Freely distributable.
  6. **
  7. **  :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #ifdef DO_MENUS
  15.  
  16.     /* LTP_ShrinkMenu(RootMenu *Root,ItemNode *First,ItemNode *Last,UWORD Mask):
  17.      *
  18.      *  Rethink the widths of all menu items between First and Last, including
  19.      *  both the first and the last entry.
  20.      */
  21.  
  22. VOID
  23. LTP_ShrinkMenu(RootMenu *Root,ItemNode *First,ItemNode *Last,LONG Mask)
  24. {
  25.     ItemNode    *Here;
  26.     LONG         Width,MaxWidth = 0,CommandWidth = 0;
  27.  
  28.         // Determine the widths of all items, also calculate
  29.         // the command widths
  30.  
  31.     for(Here = First ; Here->Node.mln_Succ ; Here = (ItemNode *)Here->Node.mln_Succ)
  32.     {
  33.         if((Here->Flags & ITEMF_IsSub) == Mask)
  34.         {
  35.             if(!(Here->Flags & ITEMF_IsBar))
  36.             {
  37.                 struct IntuiText *IntuiText = (struct IntuiText *)Here->Item.ItemFill;
  38.  
  39.                 Width = 2 + TextLength(&Root->RPort,IntuiText->IText,strlen(IntuiText->IText)) + 2;
  40.  
  41.                 if(Here->Item.Flags & CHECKIT)
  42.                     Width += 2 + Root->CheckWidth;
  43.  
  44.                 if(Width > MaxWidth)
  45.                     MaxWidth = Width;
  46.  
  47.                 if((Width = LTP_GetCommandWidth(Root,Here)) > CommandWidth)
  48.                     CommandWidth = Width;
  49.             }
  50.         }
  51.  
  52.         if(Here == Last)
  53.             break;
  54.     }
  55.  
  56.         // Now adjust the widths of all objects
  57.  
  58.     for(Here = First ; Here->Node.mln_Succ ; Here = (ItemNode *)Here->Node.mln_Succ)
  59.     {
  60.         if((Here->Flags & ITEMF_IsSub) == Mask)
  61.         {
  62.             if(Here->Flags & ITEMF_IsBar)
  63.             {
  64.                 struct Image *Image = (struct Image *)Here->Item.ItemFill;
  65.  
  66.                 Image->Width = MaxWidth + CommandWidth - 4;
  67.             }
  68.             else
  69.             {
  70.                     // Move over the submenu items if necessary
  71.  
  72.                 if(Here->Item.SubItem)
  73.                 {
  74.                     ItemNode *Sub = (ItemNode *)((ULONG)Here->Item.SubItem - sizeof(struct MinNode));
  75.  
  76.                     FOREVER
  77.                     {
  78.                         Sub->Item.LeftEdge = MaxWidth + 2;
  79.  
  80.                         if(Sub->Item.NextItem)
  81.                             Sub = (ItemNode *)Sub->Node.mln_Succ;
  82.                         else
  83.                             break;
  84.                     }
  85.                 }
  86.             }
  87.  
  88.             Here->Item.Width = MaxWidth + CommandWidth;
  89.         }
  90.  
  91.         if(Here == Last)
  92.             break;
  93.     }
  94. }
  95.  
  96. #endif  /* DO_MENUS */
  97.